
<!-- 废物循环减碳编辑业务实现-->
<template>
  <div class="app-container">
	<div style="margin-right: 50px;">
	  <breadcrumb id="breadcrumb-container" class="breadcrumb-container"/>
      <lxsh-common-table-tool-box :pageInfo="pageInfo"></lxsh-common-table-tool-box>
      <lxsh-common-search-condition :queryParam="queryParam" :searchConditionList="searchConditionList">
        <template v-slot:toolButton>
          <el-button class="filter-item" @click="handleSearch">搜索</el-button>
          <el-button class="filter-item" @click="handleReset">重置</el-button>
        </template>
      </lxsh-common-search-condition>
      <!-- 列表 start -->
      <vxe-grid ref="tableListRef" v-bind="gridOptions" @sort-change="handleSortChange" @page-change="handlePageChange" :loading="loading" :height="tableHeight" >
      <!-- 可用按钮 start -->
        <template #reduceCount="{ row }">
          <vxe-input v-model="row.reduceCount"></vxe-input>
        </template>
      <!-- 可用按钮 end -->
        <!-- 操作列模板 start -->
        <template #week ="{row}">
            第{{row.week}}周
        </template>
        <template #operate="{ row }">
          <vxe-button type="text" @click="handleUpdateR(row)" v-if="!row.editStatus" v-permission="['cer:wasteImpro:updateReduceCount']"><span class="default-button-font-color">减碳编辑</span></vxe-button>
          <vxe-button type="text" @click="handleSaveR(row)" v-else v-permission="['cer:wasteImpro:updateReduceCount']"><span class="default-button-font-color">保存</span></vxe-button>
          <vxe-button type="text"  @click="handleUpdate(row)" v-permission="['cer:wasteImpro:update']"><span class="default-button-font-color">编辑</span></vxe-button>
          <span class="default-button-font-color" v-permission="['cer:wasteImpro:update','cer:wasteImpro:deleteByLogicBatch']">|</span>  
          <el-popconfirm title="确定删除当前数据吗？" @confirm="handleDelete(row)">
              <template #reference>
                  <vxe-button type="text" v-permission="['cer:wasteImpro:deleteByLogicBatch']"><span class="default-button-font-color">删除</span></vxe-button>
              </template>
          </el-popconfirm>
        </template>
        <!-- 操作列模板 end -->
      </vxe-grid>
      <!-- 列表 end -->
	</div>
    <!--右侧按钮工具栏start-->
    <div class="table-right-tool-bar">
      <el-col style="margin-top: 30px;"></el-col>
      <el-col style="margin-top: 30px;text-align: center;" class="button-icon" v-permission="['cer:wasteImpro:update']">
        <i class="button-icon iconfont icon-xinzeng" @click="handleCreate"></i>
      </el-col>
      <el-col style="margin-top: 30px;text-align: center;" v-permission="['cer:wasteImpro:deleteByLogicBatch']">
        <i class="button-icon iconfont icon-shanchu" icon="el-icon-delete" @click="handleDeleteBatch"></i>
      </el-col>
      <el-col style="margin-top: 30px;text-align: center;" >
        <el-button type="text"  @click="exportExcel"><i class="button-icon iconfont icon-download"></i></el-button>
      </el-col>
    </div>
    <!--右侧按钮工具栏end-->
    <!-- 编辑组件 start-->
    <cer-waste-impro-edit @editProcessSuccess="editProcessSuccess" :pageInfo="pageInfo" :isEditFormVisible="isEditFormVisible" :functionDistinguish="editFunctionType" v-if="isEditFormVisible"></cer-waste-impro-edit>
    <!-- 编辑组件 end-->
  </div>
</template>
<script lang="ts" setup>
  import CerWasteImproEdit from './cer-waste-impro-edit.vue'
  import { hooksForCommonTable} from 'hhlt-vue/src/components/Lxsh/Common/hooksForCommonTable'
  import { ref, reactive, toRefs, onMounted, Ref ,getCurrentInstance} from "vue"
  import { VxeGridInstance, VXETable } from 'vxe-table';
  import cerWasteImproApi from 'lxsh-cer-web-pc/src/api/cer/cer/cerWasteImproApi'
  import { CerWasteImpro}from 'lxsh-cer-web-pc/src/model/cer/cer/waste-impro/cer-waste-impro'
  import { IExecuteData } from 'hhlt-core/src/model/base/resultModel';
  //获取grid实例
  const tableListRef:Ref<VxeGridInstance | undefined> = ref<VxeGridInstance>()
  //初始化hooks
  const {commonData,gridOptions,handleSortChange,handlePageChange,handleSearch,handleReset,handleDelete,handleUpdate,tableHeight,editProcessSuccess,handleCreate,handleDeleteBatch} = hooksForCommonTable<CerWasteImpro>(tableListRef)  
  //设置
  commonData.pageInfo = {
    systemCode:"cer",
    pageCode:"cerWasteImpro",
    functionCode:"getListByPager",
    title:"废物循环减碳",
    params:{
      id:undefined
    }
  }
  //返回vue界面需要使用到的data
  const { loading,isEditFormVisible,editFunctionType,searchConditionList,queryParam,pageInfo} = toRefs(commonData)

  const exportExcel = () => {

    loading.value = false;
    cerWasteImproApi.exportExcel(queryParam.value,"废物循环减碳",(result: IExecuteData<String>) => {

      if(result.success){

        loading.value=false
      }
    })
  }
const vueContext = getCurrentInstance();
gridOptions.editConfig = {
  trigger: "manual",
  mode: "row",
};
const handleUpdateR = (rew: any) => {
  tableListRef.value?.setEditRow(rew);
  rew.editStatus = true;
};
const handleSaveR = (rew: any) => {
  console.log(rew, "=====点击保存");
  cerWasteImproApi.updateForm(rew, (restData) => {
    if (restData.success) {
      vueContext?.appContext.config.globalProperties.$message({
        message: "更新成功！",
        type: "success",
        duration:
          vueContext?.appContext.config.globalProperties.$messageConstants
            .messageConfig.WARN_MESSAGE_DURATION,
      });
      rew.editStatus = false;
      tableListRef.value?.clearEdit();
    } else {
      vueContext?.appContext.config.globalProperties.$message({
        message: "更新失败！" + restData.msg,
        type: "error",
        duration:
          vueContext?.appContext.config.globalProperties.$messageConstants
            .messageConfig.WARN_MESSAGE_DURATION,
      });
    }
  });
};
</script>
